package com.sainan114.pipelinestudy.strategy;

import com.sainan114.pipelinestudy.util.LogUtils;
import com.sainan114.pipelinestudy.util.PipelineParamsMap;
import com.sainan114.pipelinestudy.util.StrategyKeyValueMap;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;


import java.util.List;

/**
 * @author lgb
 * @Date: 2021/7/10
 * 根据判断结果，和其rule，来给相应的父母发短信
 */
@Component
public class MessageStrategy extends AbstractStrategy {
    private  static String SEND_MESSAGE = "";
    @Override
    public void baseProcess() {
        // 1. 判断是否有对应规则
        if (!setMessage()) {
            return;
        }
        // 2. 对每个学生进行判断
        List<String> judgeStrategy = StrategyKeyValueMap.getJudgeStrategy();
        if (CollectionUtils.isEmpty(judgeStrategy)) {
            LogUtils.infoLog("judgeStrategy is empty");
        }


        for (String judgeResult : judgeStrategy) {
            if (!StringUtils.isBlank(judgeResult) && SEND_MESSAGE.equals(judgeResult)) {
                // 执行发短信的业务
                System.out.println("发短信给父母");
            }
        }
        LogUtils.infoLog("messageStrategy is success");
    }

    private boolean setMessage() {
        String strategyRule = PipelineParamsMap.getStrategyRule();
        if (StringUtils.isBlank(strategyRule)) {
            LogUtils.infoLog("send message strategyRule is empty");
            return false;
        }
        SEND_MESSAGE = strategyRule;
        return true;
    }
}
